//主要用于生成路由所需的路由配置，但主要是把component变成真正可以引入的
export function generateIndexRouter(data){
    let indexRouter=[{
        path:'/',
        name:'base',
        component:resolve => require(['@/layouts/GlobalLayout'], resolve),
        meta:{title:'首页'},
        redirect:'/index',
        children:[
            ...generateChildRouters(data)
        ]
    },{
        "path":"*","redirect":"/404","hidden":true
    }]
    return indexRouter
}

function generateChildRouters(data){
    const routers=[]
    for(let item of data){
        let component="";
        
        component="views/"+item.component
        let componentPath = resolve => require(['@/' + component+'.vue'], resolve)
        let menu={
            path:item.path,
            name:item.name,
            redirect:item.redirect,
            component:componentPath,
            meta:{
                title:item.meta.title,
                icon:item.meta.icon,
                componentName:item.meta.componentName
            }
        }
        if (item.children && item.children.length > 0) {
            menu.children = [...generateChildRouters( item.children)];
          }
          //--update-begin----author:scott---date:20190320------for:根据后台菜单配置，判断是否路由菜单字段，动态选择是否生成路由（为了支持参数URL菜单）------
          //判断是否生成路由
          if(item.route && item.route === '0'){
            //console.log(' 不生成路由 item.route：  '+item.route);
            //console.log(' 不生成路由 item.path：  '+item.path);
          }else{
            routers.push(menu);
          }
    }
    return routers
}